//
//  ZGuessController.m
//  NewProject
//
//  Created by 陈洪鑫 on 2018/4/13.
//  Copyright © 2018年 chenIos. All rights reserved.
//

#import "ZMyController.h"
#import "ZMyListCell.h"
//#import "ZMyHeaderCell.h"
#import "ZMyTransactionController.h"
#import "ZSettingController.h"
//#import "ZBaseTableView.h"
//#import "ZGuessListCell.h"
//#import <Foundation/Foundation.h>
#import "ZWHtmlController.h"
#import "ZWAboutViewController.h"
@interface ZMyController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong) NSArray *setItems;
@end

@implementation ZMyController
- (NSArray *)setItems
{
    if (!_setItems) {
//
//        Z_Location(@"setting"),
        _setItems = @[Z_Location(@"transactionLog"),Z_Location(@"support"),Z_Location(@"about")];
    }return _setItems;
}
- (UICollectionView *)collectionView
{
    if (!_collectionView) {
        CGFloat navHeight = iPhoneX ? 88 + 34 : 64;
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - navHeight) collectionViewLayout:[UICollectionViewFlowLayout new]];
        _collectionView.backgroundColor = [UIColor colorWithHexString:@"#eaeaea"];
        [_collectionView registerNib:[UINib nibWithNibName:@"ZMyListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ZMyListCell"];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
    }return _collectionView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
}


#pragma mark -- UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return self.setItems.count;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
  
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   
    ZMyListCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"ZMyListCell" forIndexPath:indexPath];
    [cell.titleBtn setTitleColor:[UIColor colorWithHexString:@"#707275"] forState:UIControlStateNormal];
    cell.titleBtn.titleLabel.font = H_Medium4;
    [cell.titleBtn setTitle:self.setItems[indexPath.section] forState:UIControlStateNormal];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
  
}


#pragma mark -- UICollectionViewDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *item = self.setItems[indexPath.section];
    if ([item isEqualToString:Z_Location(@"transactionLog")]) {
        [self.navigationController pushViewController:[ZMyTransactionController new] animated:YES];
    }else if ([item isEqualToString:Z_Location(@"setting")]){
        [self.navigationController pushViewController:[ZSettingController new] animated:YES];
    }else if ([item isEqualToString:Z_Location(@"support")]){
        NSString *htmlPath = [[NSBundle mainBundle] pathForResource:Z_Location(@"helpArticle")
                                                             ofType:@"html"];
        NSString * htmlStr = [NSString stringWithContentsOfFile:htmlPath
                                                        encoding:NSUTF8StringEncoding
                                                           error:nil];
        ZWHtmlController *htmlControl = [[ZWHtmlController alloc]init];
        htmlControl.urlStr = htmlStr;
        htmlControl.titleStr = Z_Location(@"support");
        [self.navigationController pushViewController:htmlControl animated:YES];
    }else if ([item isEqualToString:Z_Location(@"about")]){
        ZWAboutViewController *about = [[ZWAboutViewController alloc]init];
        [self.navigationController pushViewController:about animated:YES];
    }
}
#pragma mark -- UICollectionViewDelegateFlowLayout


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat width = SCREEN_W;
//    CGFloat height = 180;

    return CGSizeMake(width, 50);
 
  
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    switch (section) {
        case 2:
            return UIEdgeInsetsZero;
            break;
        default:
            return UIEdgeInsetsMake(10, 0, 0, 0);
            break;
    }
//    return UIEdgeInsetsMake(50, 0, 0, 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section;
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;



@end
